/**
 *	操作数据库基础方法
 *	开发者：雨中磐石
 *	地址：www.rockoa.com
 *	日期：2023-07-17
 */

package com.framerock.db;

import com.framerock.baselib.CallBack;
import com.framerock.baselib.Rock;
import java.util.ArrayList;
import java.util.Map;

/**
 * 操作数据库基础方法
 * */
public class DBConn implements DBBase {

    protected String errorString      = "";

    /**
     * 加入错误信息
     * */
    protected String addError(String str)
    {
        if(!Rock.isEmpt(errorString))errorString+=";";
        errorString+=""+str;
        return str;
    }
    
    /**
     * 是否有sql错
     * */
    public Boolean isError()
    {
    	if(Rock.isEmpt(errorString))return false;
    	return true;
    }

    /**
     * 返回操作的sql
     * */
    protected String getsqlVal(Map<String, String> map)
    {
        String key,val,str="";
        int oi = 0;
        for(Map.Entry<String,String> entry:map.entrySet()){
            key = entry.getKey();
            val = entry.getValue();
            if(oi>0)str+=",";
            if(val==null) {
                val = "null";
            }else if(Rock.contain(val, "()") && val.substring(0,2).equals("()")){
                val = val.substring(2);
            }else{
                val = "'"+val+"'";
            }
            str+="`"+key+"` = "+val+"";
            oi++;
        }
        return str;
    }

    /**
     * 表名加``
     * */
    protected String chuliTable(String table)
    {
        return DB.chuliTable(table);
    }


    @Override
    public void close() { }

    @Override
    public Boolean Query(String sql) {
        return false;
    }

    @Override
    public String error() {
        return this.errorString;
    }

    @Override
    public int insert(String table, Map<String, String> map) {
        return 0;
    }

    @Override
    public Boolean insertbo(String table, Map<String, String> map) {
        return false;
    }

    @Override
    public Boolean update(String table, Map<String, String> map, String where) {
        return false;
    }

    @Override
    public Boolean update(String table, String upcont, String where) {
        return false;
    }

    @Override
    public Boolean delete(String table, String where) {
        return false;
    }

    @Override
    public Map<String, String> getOne(String sql) {
        return null;
    }

    @Override
    public Map<String, String> getOne(String table, String where) {
        return null;
    }

    @Override
    public Map<String, String> getOne(String table, String where, String fields) {
        return null;
    }

    @Override
    public ArrayList<Map<String, String>> getAll(String sql, CallBack call) {
        return null;
    }

    @Override
    public ArrayList<Map<String, String>> getAll(String sql) {
        return null;
    }

    @Override
    public int getCount(String table, String where) {
        return 0;
    }

    @Override
    public ArrayList<Map<String, String>> getColumns(String table) {
        return null;
    }

    @Override
    public String[] getAlltable(String base) {
        return new String[0];
    }

    @Override
    public String[] getAlltable() {
        return new String[0];
    }
}
